package main

import (
	"fmt"
	"sync"
	"time"
)
var goRoutineWait sync.WaitGroup
func main() {
	goRoutineWait.Add(1)
	go testFunc()
	goRoutineWait.Wait()
	// 必须给协程预留足够时间，否则协程会运行失败
	//time.Sleep(time.Second*4)
	fmt.Println("程序运行结束")
}
func testFunc(){
	for i := 1;i<=3;i++ {
		defer goRoutineWait.Done()
		fmt.Printf("第%d次运行\n",i)
		time.Sleep(time.Second)
	}
}
